package com.fxsh168.server.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.fxsh168.server.R;
import com.fxsh168.server.entitys.PushOrdersEntity;

import java.util.List;

public class PassengerInformationAdapter extends BaseAdapter {
    private Context context;
    private List<PushOrdersEntity.DataBean> pushOrdersEntityDataBeanList;
    private String id, account;
    int positionCur;

    public PassengerInformationAdapter(List<PushOrdersEntity.DataBean> pushOrdersEntityDataBeanList, Context context) {
        this.pushOrdersEntityDataBeanList = pushOrdersEntityDataBeanList;
        this.context = context;
    }


    @Override
    public int getCount() {
        return pushOrdersEntityDataBeanList.size();
    }

    @Override
    public Object getItem(int position) {
        return pushOrdersEntityDataBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    private ViewHolder viewHolder;

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.mappassengerinformationitem, null);
            viewHolder = new ViewHolder();
            viewHolder.mapPortrait = (ImageView) convertView.findViewById(R.id.mapPortrait);
            viewHolder.mapStart = (TextView) convertView.findViewById(R.id.mapStart);
            viewHolder.mapEnd = (TextView) convertView.findViewById(R.id.mapEnd);
            viewHolder.mapStartTime = (TextView) convertView.findViewById(R.id.mapStartTime);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        positionCur = position;
        PushOrdersEntity.DataBean dataBean = pushOrdersEntityDataBeanList.get(position);
        String city = dataBean.getDown().toString().trim();
        String destnation = dataBean.getAddresses().toString().trim();
        String gotime = dataBean.getGotime().toString().trim();
        id = dataBean.getId().toString().trim();
        String adress = dataBean.getAddresses().toString().trim();
        String down = dataBean.getDown().toString().trim();
        String rid = dataBean.getRoutes().toString().trim();
        if (rid.equals("2")) {
            account = dataBean.getAccount().toString().trim();
            //将获得的数据设置在相应控件上
            viewHolder.mapStart.setText(destnation);
            viewHolder.mapEnd.setText(city);
            viewHolder.mapStartTime.setText(gotime);
        } else if (rid.equals("1")) {
            account = dataBean.getAccount().toString().trim();
            id = dataBean.getId().toString().trim();
            viewHolder.mapStart.setText(adress);
            viewHolder.mapEnd.setText(down);
            viewHolder.mapStartTime.setText(gotime);
        }else if (rid.equals("4")){
            account = dataBean.getAccount().toString().trim();
            id = dataBean.getId().toString().trim();
            viewHolder.mapStart.setText(adress);
            viewHolder.mapEnd.setText(down);
            viewHolder.mapStartTime.setText(gotime);
        }
        return convertView;
    }

    class ViewHolder {
        ImageView mapPortrait;
        TextView mapStart, mapEnd, mapStartTime;
    }
}
